<template>
  <el-dialog
      v-model="typeAddWinDialogVisible"
      title="新增工装夹具类型"
      width="60%"
      @close="handleClose"
      draggable
      center
  >
    <template #default>
      <el-form :model="newType">
        <el-form-item label="类型编码">
          <el-input v-model="newType.typeEncode"/>
        </el-form-item>
        <el-form-item label="类型名称">
          <el-input v-model="newType.typeName"/>
        </el-form-item>
        <el-form-item label="是否编码管理">
          <el-radio-group v-model="newType.typeStatus">
            <el-radio :value="1" size="large">是</el-radio>
            <el-radio :value="2" size="large">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="保养维护类型">
          <el-select placeholder="请选择保养维护类型" style="width:150px" v-model="newType.typeType">
            <el-option label="定期维护" :value="1"/>
            <el-option label="按使用次数维护" :value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item label="保养周期">
          <el-input v-model="newType.typeFrequency"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="newType.typeRemark"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="addTypeSubmit">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref, watch} from "vue";
import typeRequest from "@/api/type.js";

let newType = ref({});
const props = defineProps(['flag']);
const emits = defineEmits(['cancelAdd','addComplete'])
let typeAddWinDialogVisible = ref(false);

/**
 * 关闭窗体前的回调函数
 */
function handleClose(){
  newType = ref({});
  emits("cancelAdd");
}
function cancel(){
  newType = ref({});
  emits("cancelAdd");
}
/**
 * 新增点检项目的提交按钮事件
 */
function addTypeSubmit() {
  typeRequest.insertType(newType.value, res => {
    emits("addComplete");
    typeAddWinDialogVisible.value = false;
  })
}

// 属性侦听
watch(() => props.flag, () => {
  typeAddWinDialogVisible.value = props.flag === 1;
});
</script>
<style scoped>

</style>